import { Component, Injector, OnChanges, OnInit } from '@angular/core';
import { SelectBaseComponent } from '@app/commmon/components/select.components.base';
import { HDPatrolTempListDto, HDPatrolTempServiceProxy } from '@shared/service-proxies/service-proxies';
import { CustomFormGroup } from '../../custom-form.type';
import { CustomFormEditorGroupComponent } from '../custom-form-editor-group.component';

@Component({
    selector: 'app-patrol-form-temp-select',
    templateUrl: './patrol-form-temp-select.component.html',
    styles: []
})
export class PatrolFormTempSelectComponent extends SelectBaseComponent<HDPatrolTempListDto> implements OnInit, OnChanges {

    protected getEntityVal(entity: HDPatrolTempListDto) {
        return entity ? entity.name : undefined;
    }
    protected getEntityById(id: string | number): HDPatrolTempListDto {
        return this.dataList.find(f => f.id === id);
    }
    protected getEntityId(entity: HDPatrolTempListDto): string | number {
        return entity ? entity.id : 0;
    }

    constructor(injector: Injector, private _hDPatrolTempService: HDPatrolTempServiceProxy) { super(injector); }

    ngOnInit() {
        this.getList();
    }
    previewForm(item: HDPatrolTempListDto, e: MouseEvent): void {
        // this.modalHelper.static(SaveFormComponent, { formJson: JSON.parse(item.formjson) }).subscribe(() => { });
        // this.modalHelper.static(CustomFormEditorGroupComponent, { formJson: CustomFormGroup.fromJson(JSON.parse(item.formjson)), isEditor: false }).subscribe(() => { });
        e.stopPropagation();
        this._hDPatrolTempService.getForEdit(item.id).subscribe(result => {
            this.modalHelper.static(CustomFormEditorGroupComponent, {
                formJson: CustomFormGroup.fromJson(JSON.parse(result.hdPatrolTemp.formjson)),
                isEditor: false
            }).subscribe(() => { });
        });
    }
    getList(filterText?: string) {
        this.loadingService.showLoading = true;
        this._hDPatrolTempService.getPaged(filterText, 'name', 999, 0).subscribe(result => {
            this.setDataList(result.items);
        });
    }

}
